<?php

namespace api\modules\user\controllers;

use api\modules\user\models\FollowForm;
use Yii;
use api\components\Controller;

/**
 * 用户关注表
 */
class FollowController extends Controller {

    public $modelClass = 'api\modules\user\models\FollowSearch';

    /**
     * {@inheritdoc}
     */
    public function actions() {
        return [
            'view' => [
                'class' => 'yii\rest\ViewAction',
                'modelClass' => $this->modelClass,
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    protected function rules() {
        return [
            [
                'allow' => true,
                'roles' => ['@'],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    protected function verbs() {
        return [
            'attention' => ['POST'],
            'remark' => ['POST'],
        ];
    }

    /**
     * 关注列表
     * @inheritdoc
     */
    public function actionIndex() {
        /* @var $modelClass \api\modules\user\models\FollowSearch */
        $modelClass = new $this->modelClass;
        $modelClass->setToken($this->token);
        return $modelClass->search();
    }

    /**
     * 关注/取消关注
     */
    public function actionAttention(){
        $model = new FollowForm();
        $model->setToken($this->token);

        return $model->follow(Yii::$app->request->post());
    }

    /**
     * 关注备注
     */
    public function actionRemark(){
        $model = new FollowForm();
        $model->setToken($this->token);

        return $model->remark(Yii::$app->request->post());
    }

}
